Thread: sin_zero[8]

  1. #1
    Registered User
    Join Date
    Jul 2008
    Location
    Denmark
    Posts
    22

    sin_zero[8]

    Hello World!

    In the sockaddr_in structure...

    Code:
            struct sockaddr_in {
            short int        sin_family;  
            unsigned short   int sin_port;    
            struct in_addr   sin_addr;    
            unsigned char    sin_zero[8];
        };
    What is the sin_zero char good for?... You after all just fill it up with "\0"...

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Google. Networking tutorial. Networking book. In that order perhaps.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Google: http://209.85.173.104/search?q=cache...lnk&cd=2&gl=ca
    The POSIX specification requires only three members in the structure: sin_family, sin_addr, and sin_port. It is acceptable for a POSIX-compliant implementation to define additional structure members, and this is normal for an Internet socket address structure. Almost all implementations add the sin_zero member so that all socket address structures are at least 16 bytes in size.
    It's kind of like structure padding, in case extra fields need to be added in the future, I'd guess.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Location
    Denmark
    Posts
    22
    Thanks alot...

Popular pages Recent additions subscribe to a feed